//
//  USChatTextCell.m
//  us
//
//  Created by karry on 2025/4/6.
//

#import "USChatTextCell.h"

@implementation USChatTextCell

- (void)setupView{
    [super setupView];
    
    self.bubbleView = [UIView new];
    self.bubbleView.layer.cornerRadius = 14;;
    [self.messageContentView addSubview:self.bubbleView];
    
    self.messageLabel = [UILabel new];
    self.messageLabel.font = [UIFont systemFontOfSize:16];
    self.messageLabel.textColor = UIColor.whiteColor;
    self.messageLabel.numberOfLines = 0;
    [self.bubbleView addSubview:self.messageLabel];
    
    // bubbleView 约束绑定 messageContentView
    [self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.messageContentView);
    }];
    
    // messageLabel 约束到 bubble 内部 padding
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.bubbleView).offset(10);
        make.right.bottom.equalTo(self.bubbleView).offset(-10);
        make.height.mas_greaterThanOrEqualTo(20);
        make.width.mas_lessThanOrEqualTo(250);
    }];

}

- (void)setMessageViewModel:(USMessageViewModel *)messageViewModel{
    [super setMessageViewModel:messageViewModel];
    
    
    EMTextMessageBody *body = (EMTextMessageBody *)messageViewModel.message.body;

    self.messageLabel.text = body.text?:@"";
    
    
    if (messageViewModel.message.direction == EMMessageDirectionSend) {
        self.bubbleView.backgroundColor = [UIColor mainRedColor];
        self.messageLabel.textColor = UIColor.whiteColor;
    }else{
        self.bubbleView.backgroundColor = [UIColor jk_colorWithHex:0xF9F9F2];
        self.messageLabel.textColor = UIColor.blackColor;
        
    }
}

@end
